import Moya

enum HomeService {
    case getGPT(prompt: String)
}

extension HomeService: TargetType {

    var baseURL: URL {
        return URL(string: "http://69.165.78.230:3000")!
    }

    var path: String {
        switch self {
        case .getGPT:
            return "/gpt"
        }
    }

    var method: Method {
        switch self {
        case .getGPT:
            return .post
        }
    }

    var sampleData: Data {
        return Data()
    }

    var task: Task {
        switch self {
        case .getGPT(let prompt):
                return .requestParameters(
                    parameters: ["prompt": prompt],
                    encoding: JSONEncoding.default
                )
        }
        //表示没有参数的网络请求
        //case .getUsers(let userId):
       // return .requestParameters(parameters: ["userId": userId], encoding: JSONEncoding.default)
    }

    var headers: [String : String]? {
        return ["Content-type": "application/json"]
    }
}

let home_provider = MoyaProvider<HomeService>()
